package arch;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;

import play.BattleStage;
import play.Dialog;
import play.Guide;
import play.World;
import ui.Credits;
import ui.DataMenu;
import ui.GameOver;
import ui.Help;
import ui.MoveMenu;
import ui.Options;
import ui.PauseMenu;
import ui.StartMenu;
import util.Loader;
import util.Settings;

/**
 * The game is state-based.
 * The player will move from state to state whether by ui or level completion.
 * @author VincentLy
 */
public class Order extends StateBasedGame{

	private Input input;
	private Loader ml;
	private World w;
	private BattleStage s;
	private StartMenu sm;
	private DataMenu dm;
	private PauseMenu pm;
	private MoveMenu mm;
	private Options o;
	private Help h;
	private Credits c;
	private Guide g;
	private Dialog di;
	private GameOver go;

	public Order(){super("A Thief on a Journey");}

	/**
	 * Adds the states to the game and instantiates the different states.
	 * @author VincentLy
	 */
	public void initStatesList(GameContainer gc) throws SlickException {
		ml = new Loader();
		w = new World();
		s = new BattleStage();
		sm = new StartMenu();
		o = new Options();
		h = new Help();
		c = new Credits();
		pm = new PauseMenu();
		dm = new DataMenu();
		mm = new MoveMenu();
		g = new Guide();
		di = new Dialog();
		go = new GameOver();
		addState(ml);
		addState(w);
		addState(s);
		addState(sm);
		addState(dm);
		addState(o);
		addState(h);
		addState(c);
		addState(pm);
		addState(mm);
		addState(g);
		addState(di);
		addState(go);
		input = gc.getInput();
		super.enterState(ml.getID());
	}	
	
	/**
	 * Handles issues as needed when switching game states.
	 * @author VincentLy
	 */
	public void enterState(int id){
		Settings.prevState = getCurrentStateID();
		if(Settings.prevState == Settings.sID || Settings.prevState == Settings.wID)
			getContainer().getGraphics().copyArea(Settings.pause,0,0);
		if(Settings.prevState == Settings.sID)
			Settings.gameState = Settings.sID;
		if(Settings.prevState == Settings.wID)
			Settings.gameState = Settings.wID;
		Settings.time = System.currentTimeMillis();
		input.clearKeyPressedRecord();	
		super.enterState(id);
	}
}